﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MockPrjTeam2.DAO;
using System.Data;
using MockPrjTeam2.Entity;
namespace MockPrjTeam2.Biz
{
    public class OrganizationBuz
    {
        private OrganizationDao organizationDao;
        public OrganizationBuz()
        {
            organizationDao = new OrganizationDao();
        }
        //method GetAllOrganizations()
        public DataTable GetAllOrganizations()
        {
            return organizationDao.GetAllOrganizations();
        }
        //method GetOrganizationsInActive()
        public DataTable GetOrganizationsInActive()
        {
           
            return organizationDao.GetOrganizationsInActive();
        }
      
        //method GetOrganizationById()
        public Organization GetOrganizationById(int organizationId)
        {
            Organization org = new Organization();
            DataTable dt = new DataTable();
            dt = OrganizationDao.Instance.GetOrganizationById(organizationId);
            foreach (DataRow dr in dt.Rows)
            {

                org.OrganizationName = dr["OrganizationName"].ToString();
                org.ShortDescription = dr["ShortDescription"].ToString();
                org.AddressLine1 = dr["AddressLine1"].ToString();
                org.AddressLine2 = dr["AddressLine2"].ToString();
                org.AddressLine3 = dr["AddressLine3"].ToString();
                org.CityTown = dr["CityTown"].ToString();
                org.County = dr["County"].ToString();
                org.PostCode = dr["PostCode"].ToString();
                org.BussinessType = dr["BussinessTypeName"].ToString();
                org.SicCode = dr["SICCode"].ToString();
                org.ContactName = dr["ContactName"].ToString();
                org.FullDescription = dr["FullDescription"].ToString();
                org.PhoneNumber = dr["PhoneNumber"].ToString();
                org.Fax = dr["Fax"].ToString();
                org.Email = dr["Email"].ToString();
                org.WebAddress = dr["WebAddress"].ToString();
                org.CharityNumber = dr["CharityNumber"].ToString();
                org.CompanyNumber = dr["CompanyNumber"].ToString();
                org.CountryId = Convert.ToInt32(dr["CountryID"]);
                org.AddressId = Convert.ToInt32(dr["AddressID"]);
                org.BusinessTypeId = Convert.ToInt32(dr["BussinessTypeID"]);
                org.ContactId = Convert.ToInt32(dr["ContactID"]);
                 org.OrganizationId =Convert.ToInt32(dr["OrgID"]);
                org.OrganizationSpecialism = dr["OrganizationSpecialism"].ToString();
                org.ServiceDisabilities = dr["ServiceDisabilities"].ToString();
                org.ServiceBarriers = dr["ServiceBarriers"].ToString();
                org.ServiceBenefits = dr["ServiceBenefits"].ToString();
                org.ServiceCircumstances = dr["ServiceCircumstances"].ToString();
                org.ServiceEthnicity = dr["ServiceEthnicity"].ToString();
                org.Accreditation = dr["Accreditation"].ToString();
                org.PreferredOrganization =Convert.ToBoolean(dr["PreferredOrganization"]);
            }
            return org;

        }
        //method AddOrganization()
        public bool AddOrganization(Organization organization, List<int> programmeIds,List<int>serviceIds )
        {
             bool retVal = false;
            try
            {
            var newId = organizationDao.AddOrganizations(organization);
            organizationDao.AddOrganizationProgram(newId, programmeIds);
            organizationDao.AddOrganizationService(newId, serviceIds);
            return true;
            }
                
            catch (Exception ex)
            {
                ////Log here
            }
            return retVal;
        }
  
        //method UpdateOrganization()
        public bool UpdateOrganization(Organization organization)
        {
           
              
            return organizationDao.UpdateOrganizations(organization);
        }
        public bool UpdateOrganizationPro(int orgId, List<int> programIds)
        {
            return organizationDao.UpdateOrganizationProgram(orgId,programIds);
        }
        public bool UpdateOrganizationServ(int organizationId, List<int> serviceIds)
        {
            return organizationDao.UpdateOrganizationService(organizationId, serviceIds);
        }
       // Method SetActiveOrganizations()
        public bool SetActiveOrganization(int organizationId, bool status)
        {
            return organizationDao.SetActiveOrganization(organizationId, status);
        }
        public bool SetOrganizationInActive(int organizationId, bool status)
        {
            return organizationDao.SetOrganizationInActive(organizationId, status);
        }
        //method FilterOrganizationByLetters()
        public DataTable FilterOrganizationByLetters(string organizationName, int flag)
        {
            return organizationDao.FilterOrganizationByLetters(organizationName, flag);
        }
        //method CheckOrganizationNameExist()
       public int CheckOrganizationNameExist(string orgName)
       {
           return organizationDao.CheckOrganizationNameExist(orgName);
       }
           //method GetOrganizationServiceByOrgId()
       public DataTable GetOrganizationServiceByOrgId(int orgId)
       {
           return organizationDao.GetOrganizationServiceByOrgId(orgId);
       }
         //method GetOrganizationServiceByOrgId()
       public DataTable GetOrganizationProgrammeByOrgId(int orgId)
       {
           return organizationDao.GetOrganizationProgrammeByOrgId(orgId);
       }
    }
}